
package com.stchou.superbrowser.ui.widget;

import android.content.Context;
import android.util.AttributeSet;
import android.webkit.WebSettings;
import android.webkit.WebSettings.PluginState;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.ProgressBar;

public class SuperWebview extends WebView
{
    private ProgressBar m_progressBar;
    private SuperImageButton m_stopButton;
    /**
     * @param context
     * @param attrs
     */
    public SuperWebview(Context context, AttributeSet attrs)
    {
        super(context, attrs);
    }
    
    public SuperWebview(Context context)
    {
        super(context);
    }

   
    /**
     * @param progressBar the progressBar to set
     */
    public void setProgressBar(ProgressBar progressBar)
    {
        this.m_progressBar = progressBar;
    }
    
    
    /**
     * @param stopButton the stopButton to set
     */
    public void setStopButton(SuperImageButton stopButton)
    {
        this.m_stopButton = stopButton;
    }

    public void registerSmart()
    {
        WebSettings webSettings = getSettings();
        webSettings.setJavaScriptEnabled(true);
        webSettings.setSupportZoom(true);
        webSettings.setPluginState(PluginState.ON);
        webSettings.setPluginsEnabled(true);
        // 优先使用缓存：
        webSettings.setCacheMode(WebSettings.LOAD_CACHE_ELSE_NETWORK);
        
        setWebViewClient(new WebViewClient()
        {
            public boolean shouldOverrideUrlLoading(WebView view, String url)
            {
                view.loadUrl(url);
                return true;
            }
        });
        setWebChromeClient(new SuperWebviewChromeClient(m_progressBar,m_stopButton));
    }
}
